package cn.ganzhiqiang.ares.context;

import com.duitang.boot.actuatecache.RedisClientHelper;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;

import redis.clients.jedis.JedisPoolConfig;

/**
 * @author nanxuan
 * @since 2017/12/19
 **/

@Configuration
public class CacheConfig {

  @Value("${redis.cache.host}")
  private String redisHost;

  @Value("${redis.cache.port}")
  private int redisport;

  @Bean(name = {"redisPersist", "redisCache", "redisCounter", "redisSession"})
  public StringRedisTemplate redisTemplate() {
    JedisPoolConfig config = RedisClientHelper.createConfig(20, 10, 3000, false, false);
    JedisConnectionFactory factory = RedisClientHelper.createFactory(redisHost, redisport, 0, true, config);
    return RedisClientHelper.createStringTemplate(factory);
  }
}
